package com.petshop.controller;

import com.petshop.dto.PetOrder;
import com.petshop.pojo.PetProduct;
import com.petshop.service.PetProductService;
import com.petshop.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("petGood")
@CrossOrigin
@Slf4j
public class PetProductController {
    @Autowired
    private PetProductService petProductService;

    /*
    增加一个宠物商品信息
     */
    @PostMapping("insertPetProduct")
    public Result insertPetProduct(@RequestBody PetProduct petProduct) {
        Result result = petProductService.insertPetProduct(petProduct);
        return result;
    }

    /*
    下架宠物商品
     */
    @GetMapping("outPetProduct")
    public Result outPetProduct(Integer goodId) {
        Result result = petProductService.outPetProduct(goodId);
        return result;
    }

    /*
    批量下架宠物商品
     */
    @PostMapping("outBatchPetProduct")
    public Result outBatchPetProduct(@RequestBody ArrayList<Integer> idList) {
        Result result = petProductService.outBatchPetProduct(idList);
        return result;
    }

    /*
    修改宠物商品信息
     */
    @PostMapping("updatePetProduct")
    public Result updatePetProduct(@RequestBody PetProduct petProduct) {
        Result result = petProductService.updatePetProduct(petProduct);
        return result;
    }

    /*
    查询所有宠物商品列表
     */
    @GetMapping("queryPetProduct")
    public Result queryAllPetProduct(String goodName, String goodCategory, Integer pageCount, Integer productPerPage) {
        Result result = petProductService.queryPetProduct(goodName, goodCategory, pageCount, productPerPage);
        return result;
    }

    /*
    仅仅查询第一页商品
     */
    @GetMapping("queryFirstPetProduct")
    public Result queryFirstPetProduct(String goodName, String goodCategory, Integer pageCount, Integer productPerPage) {
        Result result = petProductService.queryFirstPetProduct(goodName, goodCategory, pageCount, productPerPage);
        return result;
    }

    /*
    根据宠物商品id查询商品信息
     */
    @GetMapping("queryPetProductById")
    public Result queryProductById(Integer goodId) {
        Result result = petProductService.queryPetProductById(goodId);
        return result;
    }

    /*
    购买一个宠物
     */
    @PostMapping("buyPetProduct")
    public Result buyPetProduct(@RequestBody PetOrder petOrder, @RequestHeader("Authorization") String token) {
        Result result = petProductService.buyPetProduct(petOrder, token);
        return result;
    }
}
